package codeMonkeyClock;

//import static org.junit.Assert.*;

import java.util.Date;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 *  ClockTest - JUnit test for class Clock
 *  
 *  Copyright (C) 2013  Samantha Lycett
 *  
 *  This file is part of CodeMonkeyClock.
 *
 *  CodeMonkeyClock is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  any later version.
 *
 *  CodeMonkeyClock is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with CodeMonkeyClock.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * 
 * @author  Samantha Lycett
 * @created 13 June 2013
 */
public class ClockTest {

	static Clock thisClock;
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		System.out.println("** Clock JUnit Tests **");
		thisClock = Clock.getClock();
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		System.out.println("** END Clock JUnit Tests **");
	}

	//////////////////////////////////////////////////////////////////////////
	
	
	
	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testGetRealTime_hhmmss() {
		System.out.println("The real time is:\t"+thisClock.getRealTime_hhmmss());
	}

	@Test
	public void testGetMonkeyTime_hhmmss() {
		System.out.println("The monkey time is:\t"+thisClock.getMonkeyTime_hhmmss());
	}
	
	@Test
	public void testGetTimes_as_ints() {
		int[] realTime 	 = thisClock.getRealTime_as_ints();
		int[] monkeyTime = thisClock.getMonkeyTime_as_ints();
		System.out.println("");
		System.out.println("- test times as integers -");
		System.out.println("Real time =\t"+realTime[0]+"-"+realTime[1]+"-"+realTime[2]);
		System.out.println("Monkey time =\t"+monkeyTime[0]+"-"+monkeyTime[1]+"-"+monkeyTime[2]);
		System.out.println("Difference =\t"+(monkeyTime[0]-realTime[0])+"-"+(monkeyTime[1]-realTime[1])+"-"+(monkeyTime[2]-realTime[2]));
	}
	
	@Test
	public void testTicking() {
		System.out.println("");
		System.out.println("- test ticking -");
		
		long t1 	= System.currentTimeMillis();
		long t2 	= System.currentTimeMillis();
		long twait 	= 5000;
		int nreps	= 5;
		
		for (int i = 0; i < nreps; i++) {
		
			while ( t2 < (t1+twait) ) {
				t2 = System.currentTimeMillis();
			}
			t1 = t2;
			
			thisClock.tick();
			System.out.println(new Date(t2));
			System.out.println("The real time is:\t"+thisClock.getRealTime_hhmmss());
			System.out.println("The monkey time is:\t"+thisClock.getMonkeyTime_hhmmss());
			
			
		}
	}
}
